package com.azier.kapacitor.script.node;

import com.azier.kapacitor.script.arg.OriginalArg;
import com.azier.kapacitor.script.method.*;
import com.azier.kapacitor.script.node.nodebind.CommonNodeBind;

import java.util.ArrayList;

/**
* 1 * @Author: luoj
* 2 * @Date: 2019/11/8 11:27
* 3
*/

/**
Join this node with other nodes. The data is joined on timestamp.
**/
/**
将这个节点与其他节点一起加入。数据在时间戳上加入。
**/
public class JoinNode extends AbstractNode implements CommonNodeBind {
    private static final String name = "join";

    public JoinNode(Node ...others) {
        super(new ArrayList<>(),new ArrayList<>(),name);
        //
        for(Node argf : others){
        this.args.add(new OriginalArg(argf.getNodeName()));
        }
    }

    /**
    Prefix names for all fields from the respective nodes. Each field from the parent nodes will be prefixed with the provided name and a . See the example below.
    **/
    /**
    各个节点中所有字段的前缀名称。父节点的每个字段都将以提供的名称和a作为前缀。请参见下面的示例。
    **/
    public JoinNode as(String ...names){
        As as = new As(names);
        super.addMethod(as);
        return this;
    }
    /**
    The delimiter for the field name prefixes. Can be the empty string.
    **/
    /**
    字段名称前缀的分隔符。可以是空字符串。
    **/
    public JoinNode delimiter(String join){
        Delimiter delimiter = new Delimiter(join);
        super.addMethod(delimiter);
        return this;
    }
    /**
    Fill the data. The fill option implies the type of join: inner or full outer.
    **/
    /**
    填写数据。 fill选项表示联接的类型：内部或完全外部。
    **/
    public JoinNode fill(Object join){
        Fill fill = new Fill(join);
        super.addMethod(fill);
        return this;
    }
    /**
    Join on a subset of the group by dimensions. This is a special case where you want a single point from one parent to join with multiple points from a different parent.
    **/
    /**
    按维度加入组的子集。这是一种特殊情况，您希望一个父级的一个点与另一个父级的多个点合并。
    **/
    public JoinNode on(String ...dims){
        On on = new On(dims);
        super.addMethod(on);
        return this;
    }
    /**
    Suppress all error logging events from this node.
    **/
    /**
    禁止来自此节点的所有错误记录事件。
    **/
    public JoinNode quiet(){
        Quiet quiet = new Quiet();
        super.addMethod(quiet);
        return this;
    }
    /**
    The name of this new joined data stream. If empty the name of the left parent is used.
    **/
    /**
    新加入的数据流的名称。如果为空，则使用左父级的名称。
    **/
    public JoinNode streamName(String join){
        StreamName streamName = new StreamName(join);
        super.addMethod(streamName);
        return this;
    }
    /**
    The maximum duration of time that two incoming points can be apart and still be considered to be equal in time. The joined data point’s time will be rounded to the nearest multiple of the tolerance duration.
    **/
    /**
    两个进入点可以分开并且仍然被认为在时间上相等的最大持续时间。加入的数据点的时间将四舍五入到公差持续时间的最接近倍数。
    **/
    public JoinNode tolerance(long interval, String durationLiteral){
        Tolerance tolerance = new Tolerance(interval, durationLiteral);
        super.addMethod(tolerance);
        return this;
    }

}